package org.rbac.action;

import java.lang.reflect.InvocationTargetException;

import javax.annotation.Resource;

import org.rbac.dao.BaseDao;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/demo")
@Controller
public class DemoAction {

    @Resource(name = "rbacBaseDao")
    private BaseDao rbacBaseDao;
    @Resource(name="transactionManager")
    private PlatformTransactionManager txManager;
    @Resource(name="txDefinition")
    private TransactionDefinition txDefinition;
    

    @ResponseBody
    @RequestMapping("/transcationTest")
    public String transcationTest() throws IllegalAccessException, InvocationTargetException {
       /* DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_COMMITTED);
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);*/
        TransactionStatus status = txManager.getTransaction(txDefinition);
        String sql = "update permission_syslog set sl_ip=?";
        int affected = 0;
        try {

             affected = rbacBaseDao.executeSQL(sql, "127.0.0.1");
             int a=affected/10;
             txManager.commit(status); 
             System.out.println("已提交");
        } catch (Exception e) {
            e.printStackTrace();
            txManager.rollback(status); 
            System.out.println("已回滚");
        }
        String msg = "受影响行数：" + affected;
        System.out.println(msg);
        return msg;

    }
}
